package com.itheima.controller;


import com.itheima.domain.db.User;
import com.itheima.service.db.TestSoulService;
import com.itheima.vo.Answers;
import com.itheima.vo.AnswersVo;
import com.itheima.vo.ReportVo;
import com.itheima.vo.TopicVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/testsoul")
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;

    @GetMapping("/findAll")
    public List<TopicVo> testSoul(HttpServletRequest request) {
        User user = (User) request.getAttribute("user");
        log.info("用户信息：{}", user);
        return testSoulService.findAllQuestions(user);
    }

    @PostMapping
    public Integer answer(@RequestBody AnswersVo answers, HttpServletRequest request) {
        log.info("用户答案：{}", answers);
        User user = (User) request.getAttribute("user");
        return testSoulService.answer(answers,user);

    }

    @GetMapping("/report/{id}")
    public ReportVo report(@PathVariable Long id) {
        return testSoulService.report(id);
    }
}
